<?php 
/*
 * form to display customer records
*/
//check for a valid session
include("../inc_files/utils/checksession.php");
//include the page header
include("../inc_files/ui/header.php");?>
<title>View customer details</title>
<script type="text/javascript" src="../scripts/XMLHttpRequest.js"></script>
</head>
<body>
	<?php
	//add the navigation to the page
	include("../inc_files/ui/menu.php");

	// Create connection
	include("../inc_files/utils/dbconnection.php");
	//query for customer details
	$query ="SELECT Company, Address, City, State, PostalCode, PrimaryContactName,
		PrimaryContactEmail, PrimaryContactTelephone FROM customers WHERE CustomerID = ?;";
	if($stmt = $mysqli -> prepare($query))	{
		//bind the customerid to the query
		$stmt -> bind_param("s", $customerID);

		//sanitise the input data
		$customerID = $mysqli->real_escape_string(trim($_GET["customerid"]));

		//execute the query
		$result = $stmt -> execute();

		//store the results
		$stmt->store_result();

		//bind the results to variables
		$stmt -> bind_result($company, $address, $city, $state, $postalCode, $primaryContactName, $primaryContactEmail, $primaryContactTelephone);

		//actually fetch the results
		$stmt->fetch();

		//close the statement
		$stmt -> close();


	}
	?>
	<form action="m_updatecustomer.php" method="post">
		<table class="inputform">
			<tr>
				<td class="separatorrow" colspan="2">Company:</td>

			</tr>
			<tr>
				<td class="labelcell">Name:</td>
				<td class="formcell"><input type="text" name="company" size="54"
					value="<?php echo $company ?>"></td>
			</tr>
			<tr>
				<td class="labelcell">Address:</td>
				<td class="formcell"><textarea rows="5" cols="40" name="address"><?php echo str_replace("\\r\\n", PHP_EOL, trim($address)) ?>
					</textarea>
				</td>
			</tr>

			<tr>
				<td class="labelcell">City:</td>
				<td class="formcell"><input type="text" name="city"
					value="<?php echo $city ?>" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">State:</td>
				<td class="formcell"><input type="text" name="state" size="54"
					value="<?php echo $state ?>"></td>
			</tr>
			<tr>
				<td class="labelcell">Postal code:</td>
				<td class="formcell"><input type="text" name="postalcode" size="54"
					value="<?php echo $postalCode ?>" size="54">
				</td>
			</tr>
			<tr>
				<td colspan="2" style="height: 30px;"></td>
			</tr>
			<tr>
				<td class="separatorrow" colspan="2">Primary contact</td>

			</tr>
			<tr>
				<td class="labelcell">Name:</td>
				<td class="formcell"><input type="text" name="primarycontactname"
					value="<?php echo $primaryContactName ?>" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">Email:</td>
				<td class="formcell"><input type="text" name="primarycontactemail"
					value="<?php echo$primaryContactEmail ?>" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">Telephone:</td>
				<td class="formcell"><input type="text"
					name="primarycontacttelephone"
					value="<?php echo $primaryContactTelephone ?>" size="54"></td>
			</tr>
			<tr class="separatorrow">
				<td colspan="2"></td>
			</tr>
			<tr>
				<td class="separatorrow" colspan="2"></td>

			</tr>
		</table>
	</form>
	<?php
	//add the page footer
	include($_SERVER['DOCUMENT_ROOT']."/f21na/inc_files/ui/footer.php");?>
</body>
</html>
